package com.magictower.primary.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.telephony.SmsManager;
import android.text.TextUtils;

import com.magictower.primary.common.SPConstant;
import com.magictower.primary.utils.SIMUtils;

/**
 * Created by kejunzhan on 2017/12/7.
 */

public class BootCompleteReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        SharedPreferences mPref = context.getSharedPreferences(SPConstant.CONFIG, Context.MODE_PRIVATE);
        Boolean isProtect = mPref.getBoolean(SPConstant.SAFE_PROTECT, false);
        if (isProtect) {
            String sim = mPref.getString(SPConstant.SIM, null);
            if (!TextUtils.isEmpty(sim)) {
                String currentSim = SIMUtils.getSimIccId(context);
                if (!sim.equals(currentSim)) {
                    System.out.println("SIM不一样");
                    //SIM不一样
                    String phone = mPref.getString(SPConstant.SAFE_PHONE, null);
                    //发送短信至安全号码
                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage(phone, null, "sim card has change!!!", null, null);

                } else {
                    //SIM一样
                    System.out.println("SIM一样一样一样一样");
                }
            }
        }
    }
}
